

package com.hexinfo.dmpro.sparing.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hexinfo.dmpro.common.annotation.AnonymousAccess;
import com.hexinfo.dmpro.sparing.dto.BatchSyncTypeDTO;
import com.hexinfo.dmpro.sparing.dto.ColdStandbyWeekDTO;
import com.hexinfo.dmpro.sparing.dto.ScanMetadataDTO;
import com.hexinfo.dmpro.sparing.service.ColdStandbyService;
import com.hexinfo.dmpro.sparing.service.CreateTableService;
import com.hexinfo.dmpro.sparing.service.HiveToOracleService;
import org.apache.ibatis.annotations.Param;
import org.springframework.http.ResponseEntity;
import com.hexinfo.dmpro.sparing.model.ScanMetadata;
import com.hexinfo.dmpro.sparing.service.ScanMetadataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 元数据扫描表
 *
 * @author yemw
 * @date 2023-08-28 15:44:04
 */
@RestController
@AllArgsConstructor
@RequestMapping("/api/scanmetadata" )
@Api(value = "scanmetadata", tags = "元数据扫描表管理")
public class ScanMetadataController {

    private final  ScanMetadataService scanMetadataService;

    private final ColdStandbyService coldStandbyService;

    private final CreateTableService createTableService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param scanMetadata 元数据扫描表
     * WrapperEnhancer.like(scanMetadata); //自动拼接存在值sql的方法
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @AnonymousAccess
    public ResponseEntity<Object> getScanMetadataPage(Page page, ScanMetadata scanMetadata) {
        return ResponseEntity.ok(scanMetadataService.queryList(page,scanMetadata));
    }


    /**
     * 通过id查询元数据扫描表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}" )
    public ResponseEntity<Object> getById(@PathVariable("id" ) String id) {
        return ResponseEntity.ok(scanMetadataService.getById(id));
    }

    /**
     * 新增元数据扫描表
     * @param scanMetadata 元数据扫描表
     * @return R
     */
    @ApiOperation(value = "新增元数据扫描表", notes = "新增元数据扫描表")
    @PostMapping
    @AnonymousAccess
    public ResponseEntity<Object> save(@RequestBody ScanMetadata scanMetadata) {
        return ResponseEntity.ok(scanMetadataService.save(scanMetadata));
    }

    /**
     * 修改元数据扫描表
     * @param scanMetadata 元数据扫描表
     * @return R
     */
    @ApiOperation(value = "修改元数据扫描表", notes = "修改元数据扫描表")
    @PutMapping
    public ResponseEntity<Object> updateById(@RequestBody ScanMetadata scanMetadata) {
        return ResponseEntity.ok(scanMetadataService.updateById(scanMetadata));
    }

    /**
     * 通过id删除元数据扫描表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除元数据扫描表", notes = "通过id删除元数据扫描表")
    @DeleteMapping("/{id}" )
    public ResponseEntity<Object> removeById(@PathVariable String id) {
        return ResponseEntity.ok(scanMetadataService.removeById(id));
    }


    /**
     * 扫描hive元数据写入oracle元数据扫描表
     * @return R
     */
    @ApiOperation(value = "扫描hive元数据写入oracle元数据扫描表", notes = "扫描hive元数据写入oracle元数据扫描表")
    @PostMapping("/hiveMetadataToOracle")
    @AnonymousAccess
    public ResponseEntity<Object> hiveMetadataToOracle(@Param("source") String source) {
        return ResponseEntity.ok(scanMetadataService.hiveMetadataToOracle(source));
    }

    /**
     * 批量过滤/批量确认
     * @param dto
     * @return
     */
    @ApiOperation(value = "批量过滤/批量确认", notes = "批量过滤/批量确认")
    @PostMapping("/updateBatchSyncType")
    @AnonymousAccess
    public ResponseEntity<Object> updateBatchSyncType(@RequestBody BatchSyncTypeDTO dto){
        return ResponseEntity.ok(scanMetadataService.updateBatchSyncType(dto));
    }

//    @ApiOperation(value = "批量变更同步规则", notes = "批量变更同步规则")
//    @PostMapping("/syncConfIdChange")
//    @AnonymousAccess
//    public ResponseEntity<Object> syncConfIdChange(@RequestBody ScanMetadataDTO dto){
//        return ResponseEntity.ok(scanMetadataService.syncConfIdChange(dto));
//    }


    /**
     * 查询Hdfs过滤
     * @param baseName
     * @return
     */
    @ApiOperation(value = "查询Hdfs过滤", notes = "查询Hdfs过滤")
    @PostMapping("/lsHdfs")
    @AnonymousAccess
    public ResponseEntity<Object> lsHdfs(@Param("baseName") String baseName){
        return ResponseEntity.ok(scanMetadataService.lsHdfs(baseName));
    }


    /**
     * 冷备验证方案
     * @param weekDTO
     * @return
     */
    @ApiOperation(value = "冷备验证方案", notes = "冷备验证方案")
    @PostMapping("/coldStandbyWeek")
    @AnonymousAccess
    public ResponseEntity<Object> coldStandbyWeek(@RequestBody ColdStandbyWeekDTO weekDTO){
        return ResponseEntity.ok(coldStandbyService.distCPWeek(weekDTO));
    }


    @ApiOperation(value = "自动补充建表", notes = "自动补充建表")
    @GetMapping("/createTableDifference")
    @AnonymousAccess
    public ResponseEntity<Object> createTableDifference(){
        return ResponseEntity.ok(createTableService.createTableDifference());
    }

}
